<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>求平方根</title>
</head>
<body>
	<h1>求平方根示例</h1>
	<p>输入值求出</p>
	<form id="form1" name="form1">
		<input type="text" id="Num1" name="Num1" size=="20" value="">
		<input type="button" value="计算" onclick="NumSubmit();">
	</form>
	<script type="text/javascript">
		function NumSubmit() {
			InputNum = document.form1.Num1.value;
			if(isNaN(InputNum)) {
				alert("");
			} else {
				var str1 = "的平方根为: \n\n";
				var Num1,Num2;
				if(InputNum >= 0) {
					Num1 = "+" + Math.sqrt(InputNum) + "\n\n";
					Num2 = "-" + Math.sqrt(InputNum);
					alert(InputNum + str1 + Num1 + Num2);
				} else {
					if(InputNum == -1) {
						Num1 = "+i\n\n";
						Num2 = "-i";
						alert(InputNum + str1 + Num1 + Num2);
					} else {
						var k = Math.abs(InputNum);
						Num1 = "+" + Math.sqrt(k) + "i\n\n";
						Num2 = "-" + Math.sqrt(k) + "i";
						alert(InputNum + str1 + Num1 + Num2);	
					}
				}
			}	
		}

	</script>

</body>
</html>